package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class WelcomeServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)	throws IOException, ServletException {
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		if (user == null) {
 			req.setAttribute("loginurl", userService.createLoginURL("/"));
			req.getRequestDispatcher("/pages/welcome.jsp").forward(req, resp);
		} else {
			req.setAttribute("username", user.getNickname());
			req.setAttribute("logouturl", userService.createLogoutURL("/"));
			req.getRequestDispatcher("/pages/main.jsp").forward(req, resp);
		}
	}
}
